Music Object Instance Methods

In the table below, the Music Object instance methods are divided into groups based upon the areas of functionality that they relate to. You can click on a method's name to get detailed information for that method, or you can click on one of the group headings to start reading in detail about that group of methods.

 Method Name   Short Description 
Embedding
magicEmbed Lets you embed a player instance in an HTML page, so that the player instance can be controlled using the Music Object API.
preloadEmbed Lets you preload a music file into a hidden player instance, for the purpose of triggering the file to play at a later point.
stubEmbed Lets you preload a stub RMF file into a hidden player instance, specifically for the purpose of playing musical notes through that instance.
Song Control & Player Properties
doMenuItem Lets you emulate the user-selection of one of the control panel's pop-up menu options.
endVolumeFade Lets you terminate any volume fade that is currently in progress for a Music Object instance.
fadeTo Lets you fade the overall playback volume of the Music Object instance from its current volume level to a new specified volume level, over the specified amount of time.
fadeVolume Lets you fade the overall playback volume of the Music Object instance from a specified starting volume to a specified ending volume over a specified amount of time.
getAutostart Returns the autostart property of the Music Object instance.
getFileSize Returns the size of the currently loaded file, measured in bytes.
getPanelDisplay Returns a string value, indicating the Music Object instance's current control panel display type.
getPanelMode Returns a string value, indicating the Music Object instance's current control panel mode.
getPlayLength Returns the playing duration of the currently loaded file, measured in milliseconds.
getPosition Returns an integer value, indicating the currently playing file's song position.
pause Lets you pause the file that is currently being played through the Music Object instance, so that it may be resumed later.
play Lets you start a file playing that is currently loaded into a Music Object instance, or load or play a different music file than the file that is currently loaded by specifying a file URL.
setAutostart Lets you set the autostart property of the Music Object instance.
setEndTime Lets you specify the position in an RMF or MIDI file where you would like playback to stop automatically.
setLoop Lets you set the loop status of the Music Object instance.
setPanelDisplay Lets you set the control panel display type of the Music Object instance.
setPanelMode Lets you set the control panel mode of the Music Object instance.
setPosition Lets you jump to a new position in the music file that is currently being played by the Music Object instance.
setStartTime Lets you specify the position in an RMF or MIDI file, where you would like playback to start.
setVolume Lets you set the overall playback volume of the Music Object instance.
stop Lets you stop any file that is currently playing through the Music Object instance.
Note Playing
noteOff Lets you turn off a note that is currently playing through the Music Object instance.
noteOn Lets you start a note playing on a specified MIDI channel number, with a specified note number and velocity.
playNote Lets you play a note on the specified MIDI channel, of the specified note number, velocity, and duration.
Realtime Control
setChannelMute Lets you mute or unmute the specified MIDI channel.
setChannelSolo Lets you solo or unsolo the specified MIDI channel.
setController Lets you set a value for a specified MIDI controller on a specified MIDI channel.
setMonophonic Lets you set the monophonic state of a specified MIDI channel.
setProgram Lets you issue a program change message to the specified MIDI channel with the specified program number.
setTempo Lets you set the tempo (playback speed) of the music file that is playing through the Music Object instance.
setTrackMute Lets you mute or unmute the specified track.
setTrackSolo Lets you solo or unsolo the specified track.
setTransposable Lets you set whether or not the specified MIDI channel in an RMF or MIDI file is transposable.
setTranspose Lets you set the pitch transposition of the file that is currently playing through the Music Object instance.
Playback State
isPaused Returns a boolean value, indicating the current paused state of the Music Object instance.
isPlaying Returns a boolean value, indicating the current playing state of the Music Object instance.
getChannelMute Returns a boolean value, indicating the current mute status of the specified MIDI channel.
getChannelSolo Returns a boolean value, indicating the current solo status of the specified MIDI channel.
getController Returns an integer value, indicating the current value of the specified MIDI controller on the specified MIDI channel.
getLoop Returns a boolean value, indicating the current loop status of the Music Object instance.
getMonophonic Returns a boolean value, indicating the monophonic state of the specified MIDI channel.
getOutputVolume Returns an integer value, indicating the current overall output volume of the Music Object instance.
getProgram Returns an integer value, indicating the program number that is currently selected for the specified MIDI channel.
getTempo Returns an integer value, indicating the current tempo (playback speed) of the file that is playing through the Music Object instance.
getTrackMute Returns a boolean value, indicating the current mute status of the specified track.
getTrackSolo Returns a boolean value, indicating the current solo status of the specified track.
getTransposable Returns a boolean value, indicating whether or not the specified MIDI channel will be affected by the Music Object instance's transposition value
getTranspose Returns an integer value, indicating the current pitch transposition of the Music Object instance.
getVolume Returns an integer value, indicating the current volume level for the Music Object instance.
General State
getInfo Returns a string value, indicating some information about an RMF file that is currently loaded into the Music Object instance.
Callbacks
addCallbackHandler Lets you add a callback handler for a specified instance callback.
onAudibleStateChange Lets you register JavaScript code that is to be executed each time there is a change in the audible state of the Music Object instance.
onLoad Lets you register JavaScript code that is to be executed each time the Music Object instance completes loading in a file.
onMetaEvent Lets you register the function to be executed each time the Music Object instance encounters a meta event while playing an RMF or MIDI file.
onOutputVolumeChange Lets you register JavaScript code that is to be executed each time there is a change in the Music Object instance's output volume.
onPause Lets you register JavaScript code that is to be executed each time the Music Object instance enters the paused state.
onPlay Lets you register JavaScript code that is to be executed each time the Music Object instance enters the playing state.
onReady Lets you register JavaScript code that is to be executed for only the first time that the Music Object instance completes loading in its file and becomes ready for scripted control.
onStop Lets you register JavaScript code that is to be executed each time the Music Object instance enters the stopped state.

Embedding

MusicObject 2.0 introduced a new concept in Beatnik authoring and addressed many of the issues with cross-browser authoring. One of the significant changes in interactive authoring for Beatnik is that the author no longer embeds players into an HTML page with explicit HTML code, but instead uses the magicEmbed, stubEmbed, and preloadEmbed methods of the Music Object instance. The embedding methods will write the appropriate HTML into the page, depending on what browser the user has. In the case of Netscape Navigator, the embedding methods would write the HTML for a plug-in EMBED tag. And for Microsoft's Internet Explorer, the embedding methods would write the HTML for an ActiveX control OBJECT tag. The embedding methods also perform other useful steps needed in order to link a player instance with a Music Object instance.

 magicEmbed

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Basic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The magicEmbed method is the standard way to embed a player instance in an HTML page, so that the player instance can be controlled using the Music Object API.

SYNTAX    magicEmbed ( EmbedLineSTR )

Using this method is different to a pure HTML approach and requires you to create a SCRIPT block at the position in the HTML document where you would like to embed the player. You then enclose the call to the magicEmbed method within this SCRIPT block. The magicEmbed method takes care of some of the nasty little details for the author, such as the connection between the player instance and its associated Music Object instance. magicEmbed also sets up logical defaults for certain of the player's attributes so the author does not need to specify these. The magicEmbed method takes a string as a parameter - this string representing the EMBED tag that you would normally place in the HTML if you were only authoring for non-interactive music. In this string, it is also not necessary to specify the "<EMBED " text that opens the EMBED tag, nor is it necessary to use ">" to close the EMBED tag. For example, consider the following before-and-after example:

BEFORE (Using Standard HTML)
<EMBED
   SRC="my-file.rmf"
   TYPE="audio/rmf"
   WIDTH=144
   HEIGHT=60
   PLUGINSPAGE="http://www.beatnik.com/to/?player"
>
AFTER (Using the magicEmbed Method)
<SCRIPT LANGUAGE=JavaScript><!-- //

myMusicObject.magicEmbed ('SRC="my-file.rmf" WIDTH=144 HEIGHT=60');

// --></SCRIPT>

Some things to note

Authors that are coming from a background of developing for Internet Explorer and using ActiveX controls may find it curious to use the EMBED tag syntax to create a player instance that may end up being an ActiveX control if the user is browsing with IE. The rationale behind this approach is that many early Beatnik authors have been authoring for the Beatnik Plug-in for Netscape, simply because there was no ActiveX control available initially. Much of the Beatnik content is therefore still authored for a plug-in and the magicEmbed method offers an easy upgrade path for early developers because all they have to do is move their HTML EMBED tags into a JavaScript magicEmbed method. It is also beneficial to put forward only one embedding syntax for Beatnik so that authors do not need to be concerned with browser issues.

The magicEmbed method performs the following useful steps
NOTES

With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

NOTES
 preloadEmbed

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The preloadEmbed method lets you preload a music file into a hidden player instance, for the purpose of triggering the file to play at a later point.

SYNTAX    preloadEmbed ( FileUrlSTR )

The preloadEmbed method is similar to stubEmbed in that it is also a convenient short form for embedding a player. It is specifically geared towards the preloading of RMF or other files that are to be triggered as one-shots when a certain user interaction occurs in a page. The preloadEmbed method sets the WIDTH and HEIGHT attributes to 2 and uses the HIDDEN attribute to make the player invisible on the page. It also sets the AUTOSTART attribute to FALSE so that the file doesn't begin playing immediately when a page loads up, but can be triggered by the author's UI scripting. Finally, it sets the LOOP attribute to FALSE, assuming that the UI events to be sonified should only trigger one-shots that do not loop endlessly.

The following before-and-after example shows how preloadEmbed can be used in place of magicEmbed to simplify authoring. Apart from efficiency, the two statements are equivalent.

BEFORE (Using the magicEmbed method)
myMusicObject.magicEmbed (
   'SRC="trance.rmf" ' +
   'WIDTH=0 ' +
   'HEIGHT=0 ' +
   'HIDDEN ' + 
   'AUTOSTART=FALSE ' +
   'LOOP=FALSE'
);
AFTER (Using the preloadEmbed Method)
myMusicObject.preloadEmbed ('trance.rmf');

It's important to note that, while the magicEmbed method can take an EmbedLineSTR parameter, the preloadEmbed method does not accept this parameter type and can only accept a FileUrlSTR parameter. An optional additional ExtraEmbedAttributesSTR parameter lets you specify further embed attributes or override the default embed attributes that are set by this method.

VARIATIONS
NOTES

With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

NOTES
 stubEmbed

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The stubEmbed method lets you preload a stub RMF file into a hidden player instance, specifically for the purpose of playing musical notes through that instance.

SYNTAX    stubEmbed ( FileUrlSTR )

The stubEmbed method is an authoring shortcut used when an author wishes to embed a hidden player for the purposes of sonifying the user interface of a page. Embedding of a stub file is a technique used often when sonifying the user's interactions on an HTML page with musical notes or Groovoids.

Essentially, the stubEmbed method calls the magicEmbed method with preset values for the WIDTH, HEIGHT, HIDDEN, AUTOSTART, and LOOP attributes. It is assumed that the author does not wish the UI sonification player to have a visible control panel, and so both the WIDTH and HEIGHT are set to 2 pixels, and the HIDDEN attribute is present. Also, it is assumed that the player instance is possibly to be used for note playing as well as Groovoid playing. Since notes can only be played to Beatnik while a music file is being played, the player is therefore embedded with the AUTOSTART and LOOP attributes both set to TRUE. This way, the player will always be in play mode and the author will be able to send playNote and noteOn messages.

The following before-and-after example shows how the embedding of a stub file can be simplified using the stubEmbed method rather than using the magicEmbed method. Apart from efficiency, the two statements are equivalent.

BEFORE (Using the magicEmbed method)
myMusicObject.magicEmbed (
   'SRC="stub.rmf" ' +
   'WIDTH=0 ' +
   'HEIGHT=0 ' +
   'HIDDEN ' +
   'AUTOSTART=TRUE ' +
   'LOOP=TRUE'
);
AFTER (Using the stubEmbed Method)
myMusicObject.stubEmbed ('stub.rmf');

It's important to note that, while the magicEmbed method can take an EmbedLineSTR parameter, the stubEmbed method does not accept this parameter type and can only accept a FileUrlSTR parameter. This method does also not accept the optional ExtraEmbedAttributesSTR parameter that the preloadEmbed method accepts.

NOTES

With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

NOTES
Song Control & Player Properties

The methods below carry out specific actions and do not return values indicating the success of the operation. They may, therefore, not be used in assignments or conditional statements.

 doMenuItem

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The doMenuItem method lets you emulate the user-selection of one of the control panel's pop-up menu options.

SYNTAX    doMenuItem ( MenuItemNameSTR )

The doMenuItem method behaves exactly the same as if the user had actually selected that option. This method takes a string parameter, representing the name of the menu option you wish to trigger. The names for the menu options are not always the same as the text that appears for the menu options. This is described in greater detail in the definition for the MenuItemNameSTR parameter.

NOTES
 endVolumeFade

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The endVolumeFade method lets you terminate any volume fade that is currently in progress for a Music Object instance. If there is no volume fade in progress, then this method will have no effect.

SYNTAX    endVolumeFade ( )

NOTES
 fadeTo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The fadeTo method lets you fade the overall playback volume of the Music Object instance from its current volume level to a new specified volume level, over the specified amount of time.

SYNTAX    fadeTo ( FadeToVolume0to100 , FadeTimeMsINT )

VARIATIONS
NOTES
 fadeVolume

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The fadeVolume method lets you fade the overall playback volume of the Music Object instance from a specified starting volume to a specified ending volume over a specified amount of time.

SYNTAX    fadeVolume (
    StartVolume0to100 ,
    EndVolume0to100 ,
    FadeBOOLorFadeTimeMsINT ,
    FadeEndCallbackFunctionorJavaScriptSTR ,
    FadeStepCallbackFunctionorJavaScriptSTR
)

The fadeVolume method is a superset of the fadeTo method, but allows greater flexibility in control over the volume fade. In addition to specifying starting and ending volumes, you can also specify callbacks that are to be executed as part of the volume fade. The fade end callback lets you specify a callback that is to be executed when the fade has completed. And the fade advance callback lets you specify a callback to be executed for each time that the volume is adjusted during the course of the fade. Both these callbacks are helpful for synchronizing events within an HTML page to a fade that has been initiated.

SPECIAL VALUES
VARIATIONS
NOTES
 getAutostart

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getAutostart method returns the autostart property of the Music Object instance.

SYNTAX    getAutostart ( )

RETURN VALUE    AutostartBOOL

The autostart property can be set initially using the AUTOSTART embedding property, or set subsequently using the setAutostart method.

NOTES
 getFileSize

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getFileSize method returns the size of the currently loaded file, measured in bytes.

SYNTAX    getFileSize ( )

RETURN VALUE    FileSizeBytesINT

Because the value returned by this method is measured in bytes, in order to calculate the KiloByte (Kb) size of the file, you would divide the value returned by 1024. And if you wished to express the file size in MegaBytes (Mb), then you would divide the value returned by 1048576 (1024 x 1024). The following two functions will do the conversions for you...

function bytesToKb (bytes) {
	return bytes / 1024;
}

function bytesToMb (bytes) {
	return bytes / 1048576;
}

NOTES
 getPanelDisplay

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.1.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getPanelDisplay method returns a string value, indicating the Music Object instance's current control panel display type.

SYNTAX    getPanelDisplay ( )

RETURN VALUE    PanelDisplaySTR

The control panel's display type can be set initially using the DISPLAY embedding property, or subsequently via scripting using the setPanelDisplay method.

NOTES
 getPanelMode

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.1.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getPanelMode method returns a string value, indicating the Music Object instance's current control panel mode.

SYNTAX    getPanelMode ( )

RETURN VALUE    PanelModeSTR

The control panel's mode can be set initially using the MODE embedding property, or subsequently via scripting using the setPanelMode method.

NOTES
 getPlayLength

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getPlayLength method returns the playing duration of the currently loaded file, measured in milliseconds.

SYNTAX    getPlayLength ( )

RETURN VALUE    PlayLengthMsINT

This method is useful when one wishes to queue events to occur when a file has reached its end. One would set a JavaScript timeout at the same moment that a play instruction is sent to the file, as follows: setTimeout ('endOfFileFunction ()',myMusicObject.getPlayLength ()); myMusicObject.play ();. Another application would be to start straight from the middle (halfway mark) of a song by using the expression myMusicObject.setPosition (Math.round (myMusicObject.getPlayLength () / 2));

NOTES
 getPosition

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getPosition method returns an integer value, indicating the currently playing file's song position. Song position is measured in milliseconds from the beginning of a file.

SYNTAX    getPosition ( )

RETURN VALUE    SongPositionMsINT

Song position can also be set using the setPosition method.

NOTES
 pause

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The pause method lets you pause the file that is currently being played through the Music Object instance, so that it may be resumed later using either the pause or play methods.

SYNTAX    pause ( )

If a player is in a playing state when this method is called then the player will enter a paused state. If the player is in a paused state when this method is called then the player will re-enter a playing state, resuming playback at the position where it was paused. When a player is in a paused state, the isPaused method will return a value of true. If the player is in a stopped state, then calling the pause method will have no affect.

VARIATIONS
NOTES
 play

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Basic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The play method lets you start a file playing that is currently loaded into a Music Object instance, load or play a different music file than the file that is currently loaded by specifying a file URL, or resume playback of a Music Object instance that is in a paused state.

SYNTAX    play ( )

When used with no parameters, the play method will start the Music Object instance playing whichever file it currently has loaded. If the instance is already playing, then this method will have no affect and the instance will continue playing - the instance will not restart the file it is playing from the beginning. If a Music Object instance already has a file loaded, then to restart the file playing each time a certain event occurs, simply precede the play () instruction with a stop () instruction, as in myMusicObject.stop (); myMusicObject.play ();. If an instance is currently busy loading in a music file, then a play () instruction will have no affect. If the Music Object instance has been put into a paused state using the pause method, then a play () instruction will make the instance resume playing.

VARIATIONS
SPECIAL VALUES
NOTES
 setAutostart

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setAutostart method lets you set the autostart property of the Music Object instance.

SYNTAX    setAutostart ( AutostartBOOL )

The autostart property can also be set initially using the AUTOSTART embedding property. The autostart property will affect all new files that are played using the play method. The current value of the autostart property can be obtained using the getAutostart method.

NOTES
 setEndTime

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setEndTime method lets you specify the position within the currently loaded file where you would like playback to stop automatically.

SYNTAX    setEndTime ( SongPositionMsINT )

The effect of this method is to override the file's natural end position. See also the companion setStartTime method.

NOTES
 setLoop

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setLoop method lets you set the loop status of the Music Object instance.

SYNTAX    setLoop ( LoopingBOOL )

This method can be used after a file has already been loaded and effectively overrides any loop status which may have been set using the LOOP attribute in the <EMBED> tag. Loop state can be obtained through the Music Object using the getLoop method.

NOTES
 setPanelDisplay

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.1.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setPanelDisplay method lets you set the control panel display type of the Music Object instance.

SYNTAX    setPanelDisplay ( PanelDisplaySTR )

The two available types are 'SONG' and 'SYSTEM', and correspond to the accepted values for the DISPLAY embedding property. An invalid value for the PanelDisplaySTR parameter will be ignored and the control panel will stay in its current state.

NOTES
 setPanelMode

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.1.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setPanelMode method lets you set the control panel mode of the Music Object instance.

SYNTAX    setPanelMode ( PanelModeSTR )

The three available modes are 'METERS', 'SCOPE', and 'COPYRIGHT', and correspond to the accepted values for the MODE embedding property. An invalid value for the PanelModeSTR parameter will be ignored and the control panel will stay in its current state. Valid values are dependent on the control panel's current display type (see setPanelDisplay). For instance, if the current display type is 'SYSTEM', only 'METERS' and 'SCOPE' are appropriate values for the PanelModeSTR parameter. And, if the current display type is 'SONG', then only 'COPYRIGHT' is appropriate as a value for the PanelModeSTR parameter.

NOTES
 setPosition

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setPosition method lets you jump to a new position in the music file that is currently being played by the Music Object instance. Song position is measured in milliseconds from the beginning of a file.

SYNTAX    setPosition ( SongPositionMsINT )

Song position can be obtained using the getPosition method.

ISSUES
NOTES
 setStartTime

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setStartTime method lets you specify the position in an RMF or MIDI file, where you would like playback to start.

SYNTAX    setStartTime ( SongPositionMsINT )

The effect of this method is to override the song's natural beginning position.

 IMPORTANT : Due to a problem with the Player implementation of this method, any start time that you set using this method is only observed when a file is started by the user clicking on the Player control panel's play button, and not when a file is started using the Music Object play method. As a result, this method currently has limited usefulness. This problem will be fixed in a future release of the Beatnik Player.

See also the companion setEndTime method.

NOTES
 setVolume

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Basic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The setVolume method lets you set the overall playback volume of the Music Object instance.

SYNTAX    setVolume ( Volume0to100 )

Using the setVolume method has a different effect to setting the individual volumes for MIDI channels in a music file, which can be done using the setController method.

VARIATIONS
NOTES
 stop

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Basic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The stop method lets you stop any file that is currently playing through the Music Object instance.

SYNTAX    stop ( )

Stopped files may not be resumed with the pause method. To pause files so that they may be resumed, use the pause method.

VARIATIONS
NOTES
Note Playing Methods

 noteOff

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The noteOff method lets you turn off a note that is currently playing through the Music Object instance.

SYNTAX    noteOff ( MidiChannel1to16 , NoteNumber0to127 )

In order to specify the exact note to be turned off, it is necessary to specify the MIDI channel and note number values used to switch the note on. If no note is currently playing with the specified properties, this method has no effect. noteOff may also be used to turn off notes which have been turned on using the playNote method.

VARIATIONS
NOTES
 noteOn

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The noteOn method lets you start a note playing on a specified MIDI channel number, with a specified note number and velocity.

SYNTAX    noteOn ( MidiChannel1to16 , NoteNumber0to127 , Velocity0to127 )

The note turned on using this method will continue to be sustained indefinitely unless switched off using the noteOff method.

VARIATIONS
NOTES
 playNote

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The playNote method lets you play a note on the specified MIDI channel, of the specified note number, velocity, and duration.

SYNTAX    playNote ( MidiChannel1to16 , NoteNumber0to127 , Velocity0to127 , NoteDurationMsINT )

The NoteDurationMsINT parameter is measured in milliseconds (1/1000th of a second). Notes which are started using playNote may also be switched off using noteOff, even before their duration has expired. To do this, it is necessary to target the note using the correct MIDI channel, note number, and velocity used in the initial playNote call.

VARIATIONS
NOTES
Realtime Control Of Files

 setChannelMute

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setChannelMute method lets you mute or unmute the specified MIDI channel, based upon the value of the MuteStateBOOL parameter.

SYNTAX    setChannelMute ( MidiChannel0to16 , MuteStateBOOL )

Using a value of true for the MuteStateBOOL parameter will mute a channel, and using false will unmute a channel. A channel's current mute status can be obtained by using the getChannelMute method. When a value of 0 is specified for the MidiChannel0to16 parameter, then the mute state specified by the MuteStateBOOL parameter is applied to all 16 MIDI channels.

NOTES
 setChannelSolo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setChannelSolo method lets you solo or unsolo the specified MIDI channel, based upon the value of the SoloStateBOOL parameter.

SYNTAX    setChannelSolo ( MidiChannel0to16 , SoloStateBOOL )

Using a value of true for the SoloStateBOOL parameter will solo a channel and using false will unsolo a channel. A channel's current solo status can be obtained by using the getChannelSolo method. When a value of 0 is specified for the MidiChannel0to16 parameter, then the solo state specified by the SoloStateBOOL parameter is applied to all 16 MIDI channels.

NOTES
 setController

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setController method lets you set a value for a specified MIDI controller on a specified MIDI channel.

SYNTAX    setController ( MidiChannel0to16 , ControllerNumber0to127 , ControllerValue0to127 )

When a value of 0 is specified for the MidiChannel0to16 parameter, then the specified MIDI controller will be set to the specified controller value on all 16 MIDI channels.

MIDI Event Queue

The setController method has the effect of adding a continuous controller MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getController method to query the value of a specific MIDI controller that was just "set" using the setController method may not return the value that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

NOTES
 setMonophonic

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setMonophonic method lets you set the monophonic state of a specified MIDI channel, based upon the value of the MonophonicStateBOOL parameter.

SYNTAX    setMonophonic ( MidiChannel0to16 , MonophonicStateBOOL )

Using a value of true for the MonophonicStateBOOL parameter will set the channel as being monophonic, and using false will restore it to being polyphonic. A channel's current monophonic status can be obtained by using the getMonophonic method. Setting a channel as being monophonic only affects the playing of notes through authoring and does not affect notes being played from an RMF or MIDI file. It is, however, very useful in sonifying a user's interaction with a Web page. For instance, one can prevent graphics that are sonified with mouseover sounds from stacking up a cacophony of notes by setting a certain channel as being monophonic and then making that channel play the mouseover notes.

NOTES
 setProgram

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setProgram method lets you issue a program change message to the specified MIDI channel with the specified program number.

SYNTAX    setProgram ( MidiChannel0to16 , ProgramNumber0to255 )

MIDI Event Queue

The setProgram method has the effect of adding a program change MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getProgram method to query the program for a specific MIDI channel that was just "set" using the setProgram method may not return the program that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

VARIATIONS
NOTES
 setTempo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setTempo method lets you set the tempo (playback speed) of the music file that is playing through the Music Object instance.

SYNTAX    setTempo ( TempoBPM0to300 )

Because the setTempo method sets the tempo to a new absolute value which is not relative to the current playing tempo, in order to set a playback tempo that is relative to the current tempo you should use the getTempo method first to poll the current playing tempo, then use JavaScript to modify that value (eg. add to it or multiply it by a factor), and then finally call the setTempo method with that new modified value, as in the statement...

myMusicObject.setTempo (myMusicObject.getTempo () + 10)

The setTempo method should only be used while a song is playing and has no effect if a song is stopped. Playing automatically resets any tempo which was set while a song was stopped to the song's internal tempo setting. Tempo is also reset each time the Beatnik Player loops a music file as a result of the LOOP attribute being set to true. This may be a problem when creating certain types of interactive musical experiences. As a workaround for this, you can insert LOOPSTART and LOOPEND marker events into the file to ensure that an RMF or MIDI file loops indefinitely without resetting tempo (and other settings). This internal looping mechanism is documented in more detail in the Beatnik Editor documentation. Add the LOOPSTART marker a fraction after the beginning of the file and right after any initialization events so that these also don't get re-triggered. If the LOOPSTART point is only a few ticks after the beginning of the file, then you won't even notice the tiny amount that is lost from the playback time.

NOTES
 setTrackMute

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setTrackMute method lets you mute or unmute the specified track, based upon the value of the MuteStateBOOL parameter.

SYNTAX    setTrackMute ( TrackNumber0to64 , MuteStateBOOL )

Using a value of true for the MuteStateBOOL parameter will mute a track, and using a value of false will unmute a track. A track's current mute status can be obtained by using the getTrackMute method.

SPECIAL VALUES
NOTES
 setTrackSolo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setTrackSolo method lets you solo or unsolo the specified track, based upon the value of the SoloStateBOOL parameter.

SYNTAX    setTrackSolo ( TrackNumber0to64 , SoloStateBOOL )

Using a value of true for the SoloStateBOOL parameter will solo a track, and using a value of false will unsolo a track. A track's current solo status can be obtained by using the getTrackSolo method.

SPECIAL VALUES
NOTES
 setTransposable

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   2.0.0 
 File Types Supported   RMF, MIDI 
 

The setTransposable method lets you set whether or not the specified MIDI channel in an RMF or MIDI file is transposable.

SYNTAX    setTransposable ( MidiChannel0to16 , TransposableBOOL )

By default, all MIDI channels excepting the percussion channel (channel 10) are transposable, unless set otherwise using this method. If a MIDI channel is transposable, then the musical notes playing on that channel will be affected / offset by the transposition setting for the Music Object instance (as set using the setTranspose method).

On the other hand, if a MIDI channel is not transposable, then the transposition setting for the instance will have no affect on the musical notes that play through that channel. This is particularly useful for RMF files that contain MIDI channels that are playing custom instrument drum loops. If such channels were to be transposed along with the other channels in the music file, then the tempo of the drum loops would be affected as the drum loop samples are pitch-shifted, creating undesirable chaos in the overall rhythm of the music.

Another useful application for the non-transposable state is the case where a MIDI channel is playing percussion instruments in pitched mode using NRPN640 (see the Beatnik Editor documentation) to achieve "talking drum" effects. It is most likely that such percussion effects will not be in the specific key of the melodic elements of the musical arrangement, and transposing them would produce inappropriate results. By setting such MIDI channels to be non-transposable, problems like this can be avoided when transposing the music using the setTranspose method.

You can toggle the transposable state for a specific MIDI channel by using the getTransposable method in conjunction with the setTransposable method, as in the example myMusicObject.setTransposable (!myMusicObject.getTransposable (13));.

NOTES
 setTranspose

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The setTranspose method lets you set the pitch transposition of the file that is currently playing through the Music Object instance. Pitch transposition is measured in musical half steps.

SYNTAX    setTranspose ( MusicalIntervalsINT )

The pitch transposition set by this method is not a cumulative value. ie. If you use the statement setTranspose (12), the file will transpose up by a complete octave but, if you execute that statement again, the file will not transpose up again by an octave but simply stay transposed by one octave. So, it also follows that if you use the statement setTranspose (0), then the file will return to playing at its normal pitch.

NOTES
Obtaining Playback State Information

All of the methods listed below return values that indicate state information about the Music Object instance. They may be used in assignment statements, conditional statements, or expressions. The type of the value returned by each method (ie. string, integer, or boolean) is specified in the description for each method.

 isPaused

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The isPaused method returns a boolean value, indicating the current paused state of the Music Object instance.

SYNTAX    isPaused ( )

RETURN VALUE    PausedBOOL
true = is paused
false = is not paused (could be playing or stopped)

The isPaused method returns a value of true if the instance is currently in a paused state, or a value of false if the instance is in a playing or stopped state. See also the isPlaying method.

NOTES
 isPlaying

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The isPlaying method returns a boolean value, indicating the current playing state of the Music Object instance.

SYNTAX    isPlaying ( )

RETURN VALUE    PlayingBOOL
true = is playing
false = is not playing (could be paused or stopped)

The isPlaying method returns a value of true if the instance is currently in a playing state, or a value of false if the instance is in a paused or stopped state. See also the isPaused method.

There is no dedicated method to determine if an instance is in a stopped state, but you could easily deduce if an instance is stopped by using the isPlaying and isPaused methods in combination. If an instance is not in the playing state and is also not in the paused state, then it must be in the stopped state. The following custom function takes a Music Object instance as a parameter and returns a boolean value indicating the instance's stopped state...

function isStopped (musicObjectRef) {
   return !musicObjectRef.isPlaying () && !musicObjectRef.isPaused ();
}

One would call the above function passing the Music Object instance as a parameter, as in the statement if (isStopped (myMusicObject)) {updateButtonsDisplay ()}.

NOTES
 getChannelMute

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getChannelMute method returns a boolean value, indicating the current mute status of the specified MIDI channel.

SYNTAX    getChannelMute ( MidiChannel1to16 )

RETURN VALUE    MuteStateBOOL

A return value of true indicates that the channel is muted, and a value of false indicates that it is not muted. A channel's mute status can be set using the setChannelMute method.

NOTES
 getChannelSolo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getChannelSolo method returns a boolean value, indicating the current solo status of the specified MIDI channel.

SYNTAX    getChannelSolo ( MidiChannel1to16 )

RETURN VALUE    SoloStateBOOL

A return value of true indicates that the channel is soloed, and a value of false indicates that it is not soloed. A channel's solo status can be set using the setChannelSolo method.

NOTES

 getController

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getController method returns an integer value, indicating the current value of the specified MIDI controller on the specified MIDI channel.

SYNTAX    getController ( MidiChannel1to16 , ControllerNumber0to127 )

RETURN VALUE    ControllerValue0to127

Controller values can be set using the setController method.

MIDI Event Queue

The setController method has the effect of adding a continuous controller MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getController method to query the value of a specific MIDI controller that was just "set" using the setController method may not return the value that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

NOTES
 getLoop

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getLoop method returns a boolean value, indicating the current loop status of the Music Object instance.

SYNTAX    getLoop ( )

RETURN VALUE    LoopingBOOL

Loop state can be set either in the HTML with the LOOP attribute, or via scripting using the setLoop method.

NOTES
 getMonophonic

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getMonophonic method returns a boolean value, indicating the monophonic state of the specified MIDI channel.

SYNTAX    getMonophonic ( MidiChannel1to16 )

RETURN VALUE    MonophonicStateBOOL
true = is monophonic
false = is not monophonic (ie. is polyphonic)

A return value of true indicates that the specified MIDI channel is in monophonic mode, while a value of false indicates that the channel is in polyphonic mode. A channel's monophonic status can be set using the setMonophonic method.

NOTES
 getOutputVolume

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Basic 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getOutputVolume method returns an integer value, indicating the current overall output volume of the Music Object instance.

SYNTAX    getOutputVolume ( )

RETURN VALUE    Volume0to100

The value returned by the getOutputVolume method may be different to the value returned by the getVolume instance method, and will depend on the state of any custom volume scalars that may be registered for the instance. For a better understanding of how custom volume scalars work, consult the section Important Concepts: Custom Volume Scalars.

NOTES
 getProgram

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getProgram method returns an integer value, indicating the program number that is currently selected for the specified MIDI channel.

SYNTAX    getProgram ( MidiChannel1to16 )

RETURN VALUE    ProgramNumber0to255

A channel's program number is set initially via program change events that occur within an RMF or MIDI file, but can also be set via scripting using the setProgram method.

MIDI Event Queue

The setProgram method has the effect of adding a program change MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getProgram method to query the program for a specific MIDI channel that was just "set" using the setProgram method may not return the program that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

NOTES
 getTempo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getTempo method returns an integer value, indicating the current tempo (playback speed) of the file that is playing through the Music Object instance. Tempo is measured in BPM (beats per minute).

SYNTAX    getTempo ( )

RETURN VALUE    TempoBPM0to300

Tempo is set initially from a value that is stored within an RMF or MIDI file, but can also be set via scripting using the setTempo method.

NOTES
 getTrackMute

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getTrackMute method returns a boolean value, indicating the current mute status of the specified track.

SYNTAX    getTrackMute ( TrackNumber1to64 )

RETURN VALUE    MuteStateBOOL

A return value of true indicates that the specified track is muted, and a value of false indicates that it is not muted. A track's mute status can be set using the setTrackMute method.

NOTES
 getTrackSolo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getTrackSolo method returns a boolean value, indicating the current solo status of the specified track.

SYNTAX    getTrackSolo ( TrackNumber1to64 )

RETURN VALUE    SoloStateBOOL

A return value of true indicates that the specified track is soloed, and a value of false indicates that it is not soloed. A track's solo status can be set using the setTrackSolo method.

NOTES
 getTransposable

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   2.0.0 
 File Types Supported   RMF, MIDI 
 

The getTransposable method returns a boolean value, indicating whether or not the specified MIDI channel will be affected by the Music Object instance's transposition value (which is set using the setTranspose method).

SYNTAX    getTransposable ( MidiChannel1to16 )

RETURN VALUE    TransposableBOOL
true = is transposable
false = is not transposable

When a value of false is returned by this method, it indicates that the channel is not transposable, and when a value of true is returned, it indicates that the channel is transposable. See also the setTransposable method.

NOTES
 getTranspose

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The getTranspose method returns an integer value, indicating the current pitch transposition of the Music Object instance. Pitch transposition is measured in musical half steps.

SYNTAX    getTranspose ( )

RETURN VALUE    MusicalIntervalsINT

Transposition can be set using the setTranspose method.

NOTES
 getVolume

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The getVolume method returns an integer value, indicating the current volume level for the Music Object instance.

SYNTAX    getVolume ( )

RETURN VALUE    Volume0to100

Volume can be set initially using the VOLUME embedding property, but can also be set via scripting using the setVolume method.

VARIATIONS
NOTES
General State

The methods listed below return values that indicate general state information. The type of the value returned by each method (ie. string, integer, or boolean) is specified in the description for each method.

 getInfo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.0.0 
 File Types Supported   RMF 
 

The getInfo method returns a string value, indicating some information about an RMF file that is currently loaded into the Music Object instance. The type of information that is returned is determined by the InfoFieldNameSTR parameter.

SYNTAX    getInfo ( InfoFieldNameSTR )

RETURN VALUE    InfoFieldValueSTR

The InfoFieldNameSTR parameter passed to this method indicates the specific field of an RMF file's song information that is being requested. The possible field names are listed in the definition of the InfoFieldNameSTR parameter. Field names are not case-sensitive.

NOTES
Callbacks

Callbacks make it possible to synchronize events in an HTML page with events that occur within music or audio files. For a better understanding of how to use callbacks, consult the section Important Concepts: Callbacks.

 addCallbackHandler

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The addCallbackHandler method lets you add a callback handler to the stack of callback handlers for a specified instance callback.

SYNTAX    addCallbackHandler ( InstanceCallbackTypeSTR , HandlerJavaScriptSTR )

Using this method is equivalent to using some of the methods in the Callbacks extension, such as the addOnLoad, addOnMetaEvent, addOnPause, addOnPlay, addOnReady, and addOnStop methods. For instance, the statement myMusicObject.addCallbackHandler ('onPlay','myOnPlayHandler ()') is equivalent to the statement myMusicObject.addOnPlay ('myOnPlayHandler ()'). One thing this method allows is for callback handlers to be dynamically assigned to certain callback types, since one could use a string expression for the InstanceCallbackTypeSTR parameter to determine to which callback type the handler should be added.

VARIATIONS
NOTES
 onAudibleStateChange

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onAudibleStateChange method lets you register JavaScript code that is to be executed each time there is a change in the audible state of the Music Object instance.

SYNTAX    onAudibleStateChange ( HandlerJavaScriptSTR )

Whenever there is a change in the audible state of a Music Object instance, there is a corresponding change in the value of the instance's audible property. So, at the time that the handler for this callback is executed, the current audible state can be obtained by querying the audible instance property. For a clearer understanding of the specific conditions that result in an instance being considered audible or inaudible, consult the reference section for the audible instance property.

VARIATIONS
NOTES
 onLoad

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onLoad method lets you specify JavaScript code that is to be executed each time the Music Object instance completes loading in a file.

SYNTAX    onLoad ( HandlerJavaScriptSTR )

The onLoad callback can be used, for example, to freeze the operation of a sonified Web page until all the sound elements that the page relies upon have fully loaded in.

VARIATIONS
NOTES
 onMetaEvent

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI 
 

The onMetaEvent method lets you register the function to be executed each time the Music Object instance encounters a meta event while playing an RMF or MIDI file.

SYNTAX    onMetaEvent ( HandlerFunction )

Handler Must be a Function

Unlike other methods that register callback handlers, the onMetaEvent method only accepts a Function parameter type for the callback handler. The function that is registered as a handler for meta event callbacks must expect to receive two string parameters. The first parameter will contain a value of type MetaEventTypeSTR, indicating the type of meta event that has been encountered. The second parameter will contain a string value, indicating the value of the meta event that has been encountered. For instance, if a marker named "Chorus Starts" were encountered, then the first parameter would contain the string value "Marker" and the second parameter would contain the string value "Chorus Starts".

The possible values for the first parameter are:

TrackName events are not currently supported by the Beatnik Player, since it was decided that the sheer volume of these events clumped up at the beginning of RMF and MIDI files may produce too much load on the JavaScript interpreter and may "bring down" the JavaScript code intended to handle meta events.

Define the Handler Function First

It's very important that the function you wish to register as a handler for meta event callbacks be defined before you call the onMetaEvent method. If your handler function is not defined beforehand then your code will produce JavaScript errors and will not work correctly. For example, compare the following two code segments...

  INCORRECT
myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);

function myMetaEventHandler (metaEventType,metaEventValue) {
   // some code to handle meta events
}
  CORRECT
function myMetaEventHandler (metaEventType,metaEventValue) {
   // some code to handle meta events
}

myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);

An Example

In the following hypothetical example, we're assuming that the Music Object instance "myMusicObject" is playing a music file that contains marker events to indicate when the chorus sections start and end. The function myMetaEventHandler is registered as the meta event handler for this instance, using the statement myMusicObject.onMetaEvent (myMetaEventHandler).

//...........................
// more JavaScript code above

function myMetaEventHandler (metaEventType,metaEventValue) {
   if (metaEventType == 'Marker') {
      if (metaEventValue == 'Chorus Starts') {
         // code to SHOW chorus lyrics layer
      } else if (metaEventValue == 'Chorus Ends') {
         // code to HIDE chorus lyrics layer
      }
   }
}

myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);

// more JavaScript code below
//...........................

The function myMetaEventHandler contains conditional code to check for the markers "Chorus Starts" and "Chorus Ends" and to then update the display of the HTML page appropriately. The function myMetaEventHandler may be called many times while the music file is playing for other meta events that are encountered, but because of the conditional "if" statements, the function will only ever do something when a marker event is encountered that has either the value "Chorus Starts" or "Chorus Ends".

The specific code that you would place inside the meta event handler function will depend entirely on the types of events you wish to filter out and act upon. If you wanted, you could write your handler function so that it always does the same thing, regardless of the type or value of meta events encountered. Another possibility would be to write a handler function that always does the same thing, but for only a specific type of meta event. It all depends on the goals of your project.

VARIATIONS
NOTES
 onOutputVolumeChange

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onOutputVolumeChange method lets you register JavaScript code that is to be executed each time there is a change in the Music Object instance's output volume.

SYNTAX    onOutputVolumeChange ( HandlerJavaScriptSTR )

A change in output volume can occur as a result of...

At the time that the handler for this callback is executed, the current output volume can be obtained using the getOutputVolume instance method.

VARIATIONS
NOTES
 onPause

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onPause method lets you register JavaScript code that is to be executed each time the Music Object instance enters the paused state.

SYNTAX    onPause ( HandlerJavaScriptSTR )

A Music Object instance enters the paused state when playback is paused by the user via the pause button on the player's control panel or the "Pause" option in the player's pop-up menu, or if playback is paused via scripting with the pause method.

The onPause callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

VARIATIONS
NOTES
 onPlay

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onPlay method lets you register JavaScript code that is to be executed each time the Music Object instance enters the playing state.

SYNTAX    onPlay ( HandlerJavaScriptSTR )

A Music Object instance enters the playing state when the AUTOSTART property is set to true at the time that the instance completes loading in a file, or if playback is started by the user via the play button on the player's control panel or the "Play" option in the player's pop-up menu, or if playback is started via scripting with the play method.

The onPlay callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

VARIATIONS
NOTES
 onReady

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.1.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onReady method lets you register JavaScript code that is to be executed for only the first time that the Music Object instance completes loading in its file and becomes ready for scripted control.

SYNTAX    onReady ( HandlerJavaScriptSTR )

Compare the behavior of this callback to the onLoad callback, which is executed each time that a Music Object instance finishes loading in a new file.

VARIATIONS
NOTES
 onStop

 
 CATEGORY   Instance Method 
 MODULE   Music Object Core 
 Music Object Component - Advanced 
 Min. Player Version   1.3.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The onStop method lets you register JavaScript code that is to be executed each time the Music Object instance enters the stopped state.

SYNTAX    onStop ( HandlerJavaScriptSTR )

A Music Object instance enters the stopped state when the music file it is playing reaches its natural end and stops, or if the player is stopped by the user via the stop button on the player's control panel or the "Stop" option in the player's pop-up menu, or if the player is stopped via scripting with the stop method.

The onStop callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

VARIATIONS
NOTES